FROM python:3.13

RUN apt-get update && apt-get install -y \
    fonts-dejavu-core \
    fonts-liberation \
    fontconfig \
    && rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf /usr/share/fonts/arial.ttf
# 接收构建参数
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple/
ARG PIP_TIMEOUT=300
ARG PIP_RETRIES=10

# 设置 pip 配置
ENV PIP_INDEX_URL=${PIP_INDEX_URL}
ENV PIP_TIMEOUT=${PIP_TIMEOUT}
ENV PIP_RETRIES=${PIP_RETRIES}


# 配置 pip
RUN pip config set global.index-url ${PIP_INDEX_URL} && \
    pip config set global.timeout ${PIP_TIMEOUT} && \
    pip config set global.retries ${PIP_RETRIES}

# 安装最新版本的Poetry
RUN  pip install poetry

RUN poetry config repositories.tuna ${PIP_INDEX_URL}

# 配置Poetry
ENV POETRY_NO_INTERACTION=1 \
    POETRY_VENV_IN_PROJECT=1 \
    POETRY_CACHE_DIR=/tmp/poetry_cache \
    PYTHONUNBUFFERED=1

WORKDIR /app

# 先复制依赖文件
COPY pyproject.toml ./


# 创建一个虚拟的包结构让Poetry能够工作
RUN mkdir -p src/dicom_viewer_be_mock_xiaosai && \
    touch src/dicom_viewer_be_mock_xiaosai/__init__.py

# 安装依赖
RUN poetry lock && poetry install
# 复制实际的应用代码
COPY src/ ./src/

# 如果有其他文件，复制它们
COPY . .

# 启动应用
CMD ["poetry", "run", "python", "-m", "src.dicom_viewer_be_mock_xiaosai.__init__"]
